

package com.hazelcast.map.impl.iterator;

import com.hazelcast.map.impl.proxy.MapProxyImpl;

import javax.annotation.Nonnull;
import java.util.Iterator;
import java.util.Map;

/**
 * Iterable that provides an iterator for iterating map entries in the
 * whole cluster. It returns {@link MapIterator}.
 *
 * @param <K> the key type of map.
 * @param <V> the value type of map.
 * @see MapIterator
 */
public class MapIterable<K, V> implements Iterable<Map.Entry<K, V>> {

    private final MapProxyImpl<K, V> mapProxy;
    private final int fetchSize;
    private final int partitionCount;
    private final boolean prefetchValues;

    public MapIterable(MapProxyImpl<K, V> mapProxy, int fetchSize, int partitionCount, boolean prefetchValues) {
        this.mapProxy = mapProxy;
        this.partitionCount = partitionCount;
        this.fetchSize = fetchSize;
        this.prefetchValues = prefetchValues;
    }

    @Nonnull
    @Override
    public Iterator<Map.Entry<K, V>> iterator() {
        return new MapIterator<>(mapProxy, fetchSize, partitionCount, prefetchValues);
    }
}
